package cn.tedu.luban.order.main.controller;

import cn.tedu.luban.order.main.converter.OrderConverter;
import cn.tedu.luban.order.main.service.OrderAdminService;
import cn.tedu.luban.order.protocol.VO.AdminOrderDetailVO;
import cn.tedu.luban.order.protocol.VO.AdminOrderItemVO;
import cn.tedu.luban.order.protocol.bo.OrderBO;
import cn.tedu.luban.order.protocol.query.AdminOrderListQuery;
import com.tedu.inn.protocol.ListRecordTotalBO;
import com.tedu.inn.protocol.model.Result;
import com.tedu.inn.protocol.pager.PagerResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "订单后台接口",tags = "订单后台接口")
@RestController
@RequestMapping("admin/order")
public class OrderAdminController {
    @Autowired
    private OrderAdminService orderAdminService;
    @Autowired
    private OrderConverter orderConverter;
    @PostMapping(value = "search", produces = "application/json")
    @ApiOperation("后台订单列表")
    public Result<PagerResult<AdminOrderItemVO>> queryOrders(@RequestBody AdminOrderListQuery adminOrderListQuery) {
        ListRecordTotalBO<OrderBO> orderListTotalRecord = this.orderAdminService.queryOrders(adminOrderListQuery);
        return new Result(this.orderConverter.bo2PagerResultVO(orderListTotalRecord, adminOrderListQuery));
    }
    @GetMapping(value = "get", produces = "application/json")
    @ApiOperation("订单详情")
    public Result<AdminOrderDetailVO> detailOrder(Long id)  {
        OrderBO orderBo = orderAdminService.detailOrder(id);
        return new Result(this.orderConverter.bo2detailVo(orderBo));
    }


}
